<template>
  <div >
    <x-card >
      <div slot="content" class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="拼音码" >
                <a-input v-model="queryParam.searchValue" allow-clear placeholder="请输入"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="项目名称" >
                <a-input v-model="queryParam.searchValue" allow-clear placeholder="请输入"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="类别">
                <a-select v-model="queryParam.searchStatus" allow-clear placeholder="请选择" default-value="0">
                  <a-select-option v-for="(item,index) in statusDictTypeDropDown" :key="index" :value="item.code" >{{ item.value }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </x-card>
    <a-card :bordered="false">
      <super-table
        :scroll="{x:900}"
        :pageSize="10"
        size="small"
        ref="table"
        :columns="columns"
        :data="loadData"
        :rowKey="(record) => record.id"
      >
        <template slot="operator">
          <a-button type="primary"  icon="plus" @click="$refs.addDrawer.show()">新增</a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a-popconfirm title="确定删除吗?" @confirm="() =>clickDelete(record)">
            <a-button class="g-bt-pad-0" type="link" >删除</a-button>
          </a-popconfirm>
        </span>
      </super-table>
    </a-card>
    <add-drawer ref="addDrawer" @success="$refs.table.refresh(true)" />

  </div>

</template>

<script>

import { SuperTable, XCard} from '@/components'
import addDrawer from './addDrawer'
import { getCommonlyPrescribedList ,deleteCommonlyPrescribed} from '@/api/bd/doctorEnjoin'

export default {
  components: {
    SuperTable,
    XCard,
    addDrawer
  },
  data() {
    return {
      // 加载数据方法 必须为 Promise 对象，由于parameter自带pageNum和pageSize参数，
      // 因此queryParam不能携带pageNum和pageSize参数，否则会替换掉，可携带其他参数
      loadData: parameter => {
        return getCommonlyPrescribedList(Object.assign(parameter, this.queryParam)).then((res) => {
          return res
        })
      },
      tableData:[],
      columns: [
        { title: '序号', customRender: (text,record,index) => index+1, width:100,fixed: 'left' },
        { title: '拼音码', dataIndex: 'pyCode' ,ellipsis:true, width:100},
        { title: '项目名称', dataIndex: 'name',width:100,ellipsis:true},
        { title: '类别', dataIndex: 'typeId' ,width:100,ellipsis:true},
        { title: '数量', dataIndex: 'qty' ,ellipsis:true},
        { title: '单位', dataIndex: 'basicUnit', width:100,ellipsis:true},
        { title: '规格', dataIndex: 'spec',ellipsis:true , width:100},
        { title: '价格', dataIndex: 'price',ellipsis:true, width:100},
        { title: '公司编码', dataIndex: 'compCode' ,ellipsis:true},
        { title: '创建人', dataIndex: 'recorder', width:100},
        { title: '创建时间', dataIndex: 'recordDate' , width:100,ellipsis:true},
        { title: '备注', dataIndex: 'remark',ellipsis:true, width:100},
        { title: '编码', dataIndex: 'code',ellipsis:true, width:100},
        { title: '修改人', dataIndex: 'modifier',ellipsis:true, width:100 },
        { title: '修改时间', dataIndex: 'modifyDate',ellipsis:true, width:100},
        { title: '修改时间',scopedSlots:{ customRender: 'action' },fixed:'right',ellipsis:true, width:100},

      ],
      rowSelection: {
        selectedRowKeys: this.selectedRowKeys,
        onChange: this.onSelectChange
      },
      options: {
        alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
        rowSelection: {
          selectedRowKeys: this.selectedRowKeys,
          onChange: this.onSelectChange
        }
      },
      selectedRowKeys: [],
      statusDictTypeDropDown: [],
      form: this.$form.createForm(this),
      // 查询参数
      queryParam: {},
      loading: true, //加载状态,
      currentActiveKey: 1,
    }
  },
  methods: {
    handleOk () {
      this.$refs.table.refresh()
    },
    clickDelete(record){
      console.log(record)
      deleteCommonlyPrescribed({id:record.id}).then(res=>{
        console.log('删除结果',res)
        if(res.code==200){
          this.$message.success(res.message)
          this.$refs.table.refresh(true)
        }else{
          this.$message.warning(res.message)
        }
      })
    }
  }

}
</script>

<style lang="less" scoped>

.table-operator {
  margin-bottom: 18px;
}

/deep/ .table-search-page .ant-tabs-nav-wrap{
  background: #ffffff;
}

</style>